package sein.android.hopenote;

import java.util.ArrayList;

import sein.android.hopenote.Const.HopeNoteDb;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class Normal_Add extends Activity {
	private DBAdapter HnopenHelper;
	private SQLiteDatabase sdb;
	private	Button bt_s, bt_r;
	private	EditText et_to, et_fr;
	private	Spinner g_select, i_select;
	private	ArrayList<String> lst_group, lst_item, lst_unit;
	private	ArrayAdapter<String> adapter, adapter_item;
	private	Cursor cur_group, cur_item, list_cur;
	private	TextView tv_fr, tv_to ;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
        setContentView(R.layout.normal_add);
        
        bt_s = (Button)findViewById(R.id.btn_save);
        bt_r = (Button)findViewById(R.id.btn_resive);
        et_fr = (EditText)findViewById(R.id.fr_nomal_figure);
        et_to = (EditText)findViewById(R.id.to_nomal_figure);
        g_select = (Spinner)findViewById(R.id.group_select);
        i_select = (Spinner)findViewById(R.id.item_select);
        tv_fr = (TextView)findViewById(R.id.frView);
        tv_to = (TextView)findViewById(R.id.toView);
        
        et_fr.setVisibility(View.INVISIBLE);
        et_to.setVisibility(View.INVISIBLE);
        tv_fr.setVisibility(View.INVISIBLE);
        tv_to.setVisibility(View.INVISIBLE);
        
        
        
        HnopenHelper = new DBAdapter(this);
        sdb = HnopenHelper.getReadableDatabase();
        cur_group = sdb.query(true,HopeNoteDb.TB_ITEM, new String[] {HopeNoteDb.COL_GROUP}, null, null, null, null, null,null);
        cur_group.moveToFirst();
        lst_group = new ArrayList<String>();
        for(int i = 0; i < cur_group.getCount(); i++){
        	lst_group.add(cur_group.getString(0));
        	cur_group.moveToNext();
        }
        cur_group.close();
        //그룹 선택
        g_select.setPrompt("그룹 선택");
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lst_group);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        g_select.setAdapter(adapter);
        String qWhere = HopeNoteDb.COL_GROUP + " = '" + g_select.getSelectedItem().toString() + "'";
        //항목 선택
        
        cur_item = sdb.query(HopeNoteDb.TB_ITEM, new String[] {HopeNoteDb.COL_ITEM,HopeNoteDb.COL_UNIT}, qWhere, null, null, null, null);
        cur_item.moveToFirst();
        lst_item = new ArrayList<String>();
        lst_unit = new ArrayList<String>();
        for(int i = 0; i < cur_item.getCount(); i++){
        	lst_item.add(cur_item.getString(0));
        	lst_unit.add(cur_item.getString(1));
        	cur_item.moveToNext();
        }
        i_select.setPrompt("항목 선택");
        adapter_item = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lst_item);
        adapter_item.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        i_select.setAdapter(adapter_item);
	
	
        
	}

}
